#include "ofxIRC.h"
#include "ofxIRCConnection.h"
#include "ofxIRCListener.h"

void ofxIRC::addConnection(ofxIRCConnection* pCon) {
	connections.push_back(pCon);
}

void ofxIRC::addListener(ofxIRCListener* pListener) {
	listeners.push_back(pListener);
}

void ofxIRC::connect() {
	for(int i = 0; i < connections.size(); ++i) {
		connections[i]->connect();
	}
}

void ofxIRC::update() {
	for(int i = 0; i < connections.size(); ++i) {
		// parse incoming data.
		connections.at(i)->update();
		if (!connections.at(i)->hasMessages()) {
			continue;
		}

		// notify our listeners with the parsed messages.
		for(int j = 0; j < listeners.size(); ++j) {
			listeners.at(j)->update(
				connections.at(i)->getMessages()
			);
		}

		// and clear them.
		connections.at(i)->clearMessages();
	}
}


